#!/bin/bash
#
# Download and verify that the FDroid.apk is signed by the right PGP
# key.  The gpg key model is to trust only the key that is included in
# this script, so there is a test to check that it is starting with an
# empty keyring.
#
# To be run in a daily cronjob at a random time of day, e.g.:
#
#   0 0 * * *   perl -le 'sleep rand 86400'; ./check-fdroid-apk
#
# One instance of this is here:
# https://verification.f-droid.org/check-fdroid-apk/

set -e

curl="curl --user-agent F-Droid"
gpg="gpg"
if [ "$1" = "-v" ]; then
    set -x
    verbose=true
else
    curl="$curl --silent"
    gpg="$gpg --quiet"
    verbose=false
fi

test -e /tmp/.testfiles || mkdir /tmp/.testfiles
dldir=`mktemp -d /tmp/.testfiles/run-tests.XXXX`

export GNUPGHOME="$dldir"

key="${dldir}/key.asc"
apk="${dldir}/FDroid.apk"
asc="${apk}.asc"
log=/var/www/html/check-fdroid-apk/`date +%s`.txt

$curl --user-agent F-Droid https://f-droid.org/FDroid.apk > $apk
$curl --user-agent F-Droid https://f-droid.org/FDroid.apk.asc > $asc

fingerprint=37D2C98789D8311948394E3E41E7044E1DBA2E89

cat > $key <<- EOF
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1
Comment: GPG for Android - https://guardianproject.info/code/gnupg/

mQINBFNaZBcBEADVyvgks2gjG9VrHPvulVH62pzN2LpiD7lqLhAtpXSN/ZNgtkYp
HbRJfRcuZzBUVGhuMqIRb8/B4OY19zonHazstZAywD2ojToC0os0hxLDU2H7jVnh
HzsAuEkPR4hpzsftia0fzD4IlomQ0zP/C5K9wth2Cw+GFmxhI1aBZcrxVJhuVLpe
wSRShUva2iYNUIPvq02xFhTWwoIpRxGHeT/XdLEi+IHu031v3mlM5vU5zbI1UFMb
I7AnNByHfuKQ6PiDOyp14QzCw57bgAS8aRB9UK6e1xsVOVYIGNKs9xnErdYKJ295
DAxn/nHD+oaoVHP/NhuMmcNKK52vjG5HeZykHNqn5GAJ4uPFspWxRNCF+PnEnc28
EGGYql5U3jbIwmcZnVkKRahYRmf5ZRMyXroloeDARvC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z+9CfPO0
mYjk7nL5JYVkfXjThCF9f52gRVS6kktN67IGaayi8pgKgj4f/K4U3p0uAUgKNj4l
+TdCymiiEvhqE6EHxGfmJaUh9IofIaqiURzZGxQ8FN1BuIvJtU4SbEyTGXaB5Ys9
893KN8JX2ozmsF4k
=w75J
-----END PGP PUBLIC KEY BLOCK-----
EOF

! $gpg --list-keys | grep pub
$gpg --import $key
$gpg --list-key --fingerprint | tr -d '[:space:]' | grep $fingerprint > /dev/null
echo ${fingerprint}:6: | $gpg --import-ownertrust > /dev/null 2>&1
sha256=`sha256sum $apk`
echo $sha256 >> $log
touch ${log}.${sha256}
if $gpg --batch --trust-model always --verify $asc $apk >> $log 2>&1; then
    rm -rf $dldir
else
    echo Failed to verify $apk
    touch ${log}.failed
fi
